package com.hlxl.viewpointrest.service;

import com.liferay.portal.model.User;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by wyy on 18-5-7
 */
@Service
public class JwtTokenService {

    private final String SECRET_KEY = "Juyee";

    public String createToken(User user) {
        long currentTime = System.currentTimeMillis();
        //添加构成JWT的参数
        String token = Jwts.builder()
                .setSubject(user.getScreenName())
                .setExpiration(new Date(currentTime + 60 * 60 * 24 * 1000))
                .signWith(SignatureAlgorithm.HS512, SECRET_KEY)
                .compact();

        return token;
    }
}
